package simulateOS.entity;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 设备实体类 （其实是工具类 转换一下）
 * <p>Date: 2022/10/31
 * <p>Time: 9:39
 *
 * @Author SillyBaka
 **/
public class Device {

    public final static String DEVICE_A_NAME = "A";
    public final static String DEVICE_B_NAME = "B";
    public final static String DEVICE_C_NAME = "C";

    private final static int DEVICE_A_TYPE = 0;
    private final static int DEVICE_B_TYPE = 1;
    private final static int DEVICE_C_TYPE = 2;

    private final static Map<String,Integer> DEVICE_NAME_TO_TYPE_MAP;

    public static final Device DEFAULT_DEVICE = new Device("无设备",-1);

    static {
        DEVICE_NAME_TO_TYPE_MAP = new HashMap<>();

        DEVICE_NAME_TO_TYPE_MAP.put(DEVICE_A_NAME, DEVICE_A_TYPE);
        DEVICE_NAME_TO_TYPE_MAP.put(DEVICE_B_NAME, DEVICE_B_TYPE);
        DEVICE_NAME_TO_TYPE_MAP.put(DEVICE_C_NAME, DEVICE_C_TYPE);
    }

    private StringProperty deviceName;
    private IntegerProperty deviceId;

    public Device(){
        deviceName = new SimpleStringProperty();
        deviceId = new SimpleIntegerProperty();
    }
    public Device(String deviceName, int deviceId) {
        this();
        this.deviceName.set(deviceName);
        this.deviceId.set(deviceId);
    }

    /**
     * 根据设备的名字获取设备类型
     * @param deviceName 设备名字
     * @return 设备id
     */
    public static int getDeviceIndexByName(String deviceName){
        return DEVICE_NAME_TO_TYPE_MAP.get(deviceName);
    }

    public String getDeviceName() {
        return deviceName.get();
    }

    public StringProperty deviceNameProperty() {
        return deviceName;
    }

    public void setDeviceName(String deviceName) {
        this.deviceName.set(deviceName);
    }

    public int getDeviceId() {
        return deviceId.get();
    }

    public IntegerProperty deviceIdProperty() {
        return deviceId;
    }

    public void setDeviceId(int deviceId) {
        this.deviceId.set(deviceId);
    }
}
